c("location", "mPattern","k1", "k2", "k3", "k4", "k5", "k6", "k7", "k8", "k9", "k10", "k11", "k12")
CpGl001 <- levels(as.factor(pattern001$location))
nthMeth001 <- pattern001[pattern001$location == CpGl001[nthAmplicon],]
conversion matrix
cytosine_sites <- nchar(toString(nthMeth001[1,2])) - 1
conversion_rule <- array(c(1 - epsilon, epsilon, 0, 1), dim=c(2,2))
conversion <- conversion_rule
while(nrow(conversion) < 2^cytosine_sites)
{
conversion <- kronecker(conversion, conversion_rule)
}
conversion <- t(conversion)
creating the reads vector
binary <- function(x) if (all(x<2)) x else cbind(binary(x%/%2), x%%2)
cytosine_binary <- binary(0 : (2^cytosine_sites-1))
mPattern <- array(dim=c(2^cytosine_sites,1))
for(i in 1:2^cytosine_sites)
{
mPattern[i,1]<-paste(c("m", paste(cytosine_binary[i, ], collapse="")), collapse="")
}
counts <- array(0, dim=c(2^cytosine_sites,1))
conversion_rates <- counts
reads.data <- data.frame(mPattern=mPattern, counts=counts)
for(i in 1:2^cytosine_sites){
patternMatches <- nthMeth001$mPattern==mPattern[i,1]
if(any(patternMatches))
{
reads.data[i,2] <- nthMeth001[patternMatches, condition+2]
}
counts_sum <- sum(reads.data$counts)
reads_percent.data <- reads.data
reads_percent.data$counts <- reads.data$counts/counts_sum
likelihood <- function(varphi){
with_zeros <- (varphi %*% conversion)^reads.data$counts
likelihood <- - sum(log(with_zeros[with_zeros!=0]))
return(likelihood)
}
likelihood_opt <- function(varphi){
if(sum(varphi)>1){
likelihood_opt <- 100000
} else {
likelihood_opt <- likelihood(append(varphi, 1-sum(varphi)))}
return(likelihood_opt)
}
optimisation
size <- nrow(conversion)
starting_vector <- as.vector(reads_percent.data$counts[1:size-1])
starting_vector <- rep(1/size, size-1)
lower_vector <- rep(0,size - 1)
upper_vector <- rep(1,size - 1)
constraint matrix
constraint_matrix <- rbind(diag(size-1),rep(-1, size-1))
constraint_vector <- append(rep(0, size - 1), -1)
optim(starting_vector, likelihood_opt, lower=lower_vector, upper=upper_vector, method="L-BFGS-B")
print(constrOptim(starting_vector, likelihood_opt, grad = NULL, ui=constraint_matrix, ci=constraint_vector, method = "Nelder-Mead"))
library(QuasiSeq)
??QuasiSeq
help(QuasiSeq)
sample(1:7)
sample(1, 1:7)
sample(1:7, 1)
sample(1:7, size=1)
sample(1:6, size=1)
help(ppois)
help(gamslss)
library(gamslss)
library(gamlss)
help(gamlss)
help(union)
setdiff(sample(1:42, size=100, replace=TRUE), 1:42)
setdiff(sample(1:42, size=42, replace=TRUE), 1:42)
sample(1:42, size=42, replace=TRUE)
setdiff(1:42, sample(1:42, size=42, replace=TRUE))
setdiff(1:42, sample(1:42, size=100, replace=TRUE))
setdiff(1:42, sample(1:42, size=1000, replace=TRUE))
setdiff(1:42, sample(1:42, size=500, replace=TRUE))
setdiff(1:42, sample(1:42, size=200, replace=TRUE))
setdiff(1:42, sample(1:42, size=100, replace=TRUE))
setdiff(1:42, sample(1:42, size=150, replace=TRUE))
setdiff(1:42, sample(1:42, size=120, replace=TRUE))
setdiff(1:42, sample(1:42, size=150, replace=TRUE))
setdiff(1:42, sample(1:42, size=200, replace=TRUE))
setdiff(1:42, sample(1:42, size=42, replace=TRUE))
setdiff(1:42, sample(1:42, size=500, replace=TRUE))
setdiff(1:42, sample(1:42, size=200, replace=TRUE))
length(setdiff(1:42, sample(1:42, size=200, replace=TRUE)))
##
numberToCollect <- 42#
haveAlready <- 22#
sampleSize <- 1000#
numberToBuy <- 100#
##
samplesWithAllCollected <- 0#
for(sample in 1: sampleSize){#
numberMissing <- #
length(setdiff(1:(numberToCollect - haveAlready), #
sample(1:numberToCollect, #
size=numberToBuy, #
replace=TRUE)))#
samplesWithAllCollected <- samplesWithAllCollected + (numberMissing==0)#
}#
##
probAllCollectedEstimate <- samplesWithAllCollected/sampleSize#
cat("\n  If I buy", numberToBuy, "more, prob of having all", #
numberToCollect, "is", probAllCollectedEstimate, "\n\n")
##
numberToCollect <- 42#
haveAlready <- 22#
sampleSize <- 100000#
numberToBuy <- 100#
##
samplesWithAllCollected <- 0#
for(sample in 1: sampleSize){#
numberMissing <- #
length(setdiff(1:(numberToCollect - haveAlready), #
sample(1:numberToCollect, #
size=numberToBuy, #
replace=TRUE)))#
samplesWithAllCollected <- samplesWithAllCollected + (numberMissing==0)#
}#
##
probAllCollectedEstimate <- samplesWithAllCollected/sampleSize#
cat("\n  If I buy", numberToBuy, "more, prob of having all", #
numberToCollect, "is", probAllCollectedEstimate, "\n\n")
source("/Users/burden/Documents/My Pictures/R programs/GeoffClark.R")
log10(probAllCollectedEstimate)
source("/Users/burden/Documents/My Pictures/R programs/GeoffClark.R")
library(polyaAeppli)
dPolyaAeppli(5, 1, 1:3/4)
dPolyaAeppli(5, 1, 1:300/4)
dPolyaAeppli(5, 1:30, 1:3/4)
source("/Users/burden/Documents/Teaching : Supervising/MATH3353 bioinformatics 2014/Assignments/Submitted assignment 2/Asst2_Q2_Bhaskaran.R")
source("/Users/burden/Documents/Teaching : Supervising/MATH3353 bioinformatics 2014/Assignments/Submitted assignment 2/Asst2_Q2_Kenny.R")
source("/Users/burden/Documents/Teaching : Supervising/MATH3353 bioinformatics 2014/Assignments/Submitted assignment 2/Asst2_Q2_Schmidli.R")
source("/Users/burden/Documents/Teaching : Supervising/MATH3353 bioinformatics 2014/Assignments/Submitted assignment 2/Asst2_Q2_Thomann.R")
source("/Users/burden/Documents/Teaching : Supervising/MATH3353 bioinformatics 2014/Assignments/Submitted assignment 2/Asst2_Q3_Hunt.R")
source("/Users/burden/Documents/Teaching : Supervising/MATH3353 bioinformatics 2014/Assignments/Submitted assignment 2/Asst2_Q2_Hunt.R")
source("/Users/burden/Documents/Teaching : Supervising/MATH3353 bioinformatics 2014/Assignments/Submitted assignment 2/Asst2_Q3_Jarosz.R")
source("/Users/burden/Documents/Teaching : Supervising/MATH3353 bioinformatics 2014/Assignments/Submitted assignment 2/Asst2_Q2_Jarosz.R")
source("/Users/burden/Documents/Teaching : Supervising/MATH3353 bioinformatics 2014/Assignments/Submitted assignment 2/Asst2_Q3_Bhaskaran.R")
12.92/15*100
.8*15
42*(0.5772 + log(20))
42^2*pi^2/6
sqrt(42^2*pi^2/6)
numberToCollect <- 42#
haveAlready <- 22#
sampleSize <- 1000000#
numberToBuy <- 300
n <- numberToCollect#
k <- numberToCollect - haveAlready#
mu <- n*sum(1/(1:(n - k)#
sig <- sqrt(n^2*pi^2/6)
n <- numberToCollect#
k <- numberToCollect - haveAlready#
mu <- n*sum(1/(1:(n - k))#
sig <- sqrt(n^2*pi^2/6)
n <- numberToCollect#
k <- numberToCollect - haveAlready#
mu <- n*sum(1/(1:(n - k)))#
sig <- sqrt(n^2*pi^2/6)
mu
sig
n <- numberToCollect#
k <- numberToCollect - haveAlready#
mu <- n*sum(1/(1:(n - k)))#
sig <- sqrt(n^2*pi^2/6)#
##
x <- 1:300#
u <- (x - mu)/sig + 0.5772#
probXGumbel <- exp(-exp(-u)#
##
#	More direct calculation#
##
probXDirect <- (((n - 1)/n)^(x - 1)*(1/n))^k
probXGumbel <- exp(-exp(-u))#
##
#	More direct calculation#
##
probXDirect <- (((n - 1)/n)^(x - 1)*(1/n))^k
probXGumbel
probXDirect
plot(x, probXGumbel, type = "l")
points(x, probXDirect, type = "l", col="red"
)
probXDirect <- cumsum(((n - 1)/n)^(x - 1)*(1/n))^k
points(x, probXDirect, type = "l", col="red")
probXDirect(50, 75, 100, 150, 200, 300)
probXDirect[50, 75, 100, 150, 200, 300]
probXDirect[c(50, 75, 100, 150, 200, 300)]
probXDirect <- cumsum(((n - 1)/n)^(x - 1)*(1/n))^k#
##
plot(x, probXGumbel, type = "l")#
points(x, probXDirect, type = "l", col="red")#
exampleVals <- c(50, 75, 100, 150, 200, 300)#
cbind(exampleVals, probXDirect[exampleVals])
cbind(exampleVals, prob =probXDirect[exampleVals])
source("/Users/burden/Documents/Letters & reports etc/CT letters etc/GeoffClark.R")
dbinom(0:100,100, 0.45)
Mean <- 45
SD <- sqrt(100*0.45*0.55)
Mean + SD
Mean - SD
pbinom(0:100,100, 0.45)
pbinom(Mean + SD,100, 0.45)
pbinom(Mean - SD,100, 0.45)
pbinom(Mean + SD,100, 0.45) - pbinom(Mean - SD,100, 0.45)
(pbinom(Mean + SD,100, 0.45) - pbinom(Mean - SD,100, 0.45))*6
(pbinom(Mean + 2*SD,100, 0.45) - pbinom(Mean - 2*SD,100, 0.45))*6
classSize#
n <- 100#
p <- .45#
q <- 1 - p#
Mean <- n*p#
SD <- n*p*q#
(pbinom(Mean + SD,100, 0.45) - pbinom(Mean - SD,100, 0.45))*classSize
classSize <-6#
n <- 100#
p <- .45#
q <- 1 - p#
Mean <- n*p#
SD <- n*p*q#
(pbinom(Mean + SD,100, 0.45) - pbinom(Mean - SD,100, 0.45))*classSize
Mean
SD
sqrt(100*0.45*0.55)
classSize <-6#
n <- 100#
p <- .45#
q <- 1 - p#
Mean <- n*p#
SD <- sqrt(n*p*q)#
(pbinom(Mean + SD,100, 0.45) - pbinom(Mean - SD,100, 0.45))*classSize
classSize <-6#
n <- 100#
p <- .45#
q <- 1 - p#
Mean <- n*p#
SD <- sqrt(n*p*q)#
print((pbinom(Mean + SD,100, 0.45) - pbinom(Mean - SD,100, 0.45))*classSize)#
print((pbinom(Mean + 2*SD,100, 0.45) - pbinom(Mean - 2*SD,100, 0.45))*classSize)
139.77/35
489.03/35
1536.87/35
0.5*log(2)
log(sqrt(2))
92.5*0.8 + 18
92.5 * 0.8 + 18
39/45
37/45*60
x <- pi
x
options(digits=20)
x
options(digits=200)
options(digits=22)
x
pi
arctan(1/4)
atan(1/4)
2*asin(1)
3.1415926535897932384626433832795028841971693993
exp(1)
2.718281828459045235360287471352
-digamma(1)
0.577215664901532860606512090082
sqrt(2)
1.41421356237309504880168872420969807
options(digits=7)
1725/(52 - 4)
1725/(52 - 5)
help(constrOptim)
help(stats)
library(help = "stats")
library(PolyaAeppli)
library(polyaAeppli)
help(polyaAeppli)
polyaAeppli
biocLite("Bpest")
library(biocLite)
library(BiocInstaller)
biocLite("Bpest")
getAnywhere(estimatePatterns)
biocLite("estimatePatterns")
library(DESeq)
vignette(DESeq)
browseVignettes(package = "Biostrings")
library(Polyfit)
example(levelPValues)
help(levelPValues)
library(Polyfit)
cds <- makeExampleCountDataSet()#
cds <- estimateSizeFactors( cds )#
cds <- estimateDispersions( cds )#
nbT <- nbinomTest( cds, "A", "B" )#
pValuesDESeq <- nbT$pval # <-- Original DESeq code#
nbTPolyfit <- pfNbinomTest( cds, "A", "B" )#
pValuesPFDESeq <- nbTPolyfit$pval # <-- Polyfit repoacement
head(pValuesPFDESeq)
lP <- levelPValues(pValuesPFDESeq)
names(lP)
outTable <- cbind(origPval= pValuesPFDESeq, correctedPval=lP$pValueCorr, correctedQval=lP$pValueCorr, BH_Qval=lP$pValueCorrBH)
head(outTable)
lP <- levelPValues(pValuesPFDESeq)#
outTable <- cbind(origPval= pValuesPFDESeq, correctedPval=lP$pValueCorr, correctedQval=lP$qValueCorr, BH_Qval=lP$qValueCorrBH)#
cat("\n Original and corrected P-values from DESeq \n")#
head(pvalTab)
outTable <- cbind(origPval= pValuesPFDESeq, correctedPval=lP$pValueCorr, correctedQval=lP$qValueCorr, BH_Qval=lP$qValueCorrBH)
head(outTable)
getwd()
setwd("~/Documents/Next generation sequencing/Paper 2 Overdispersed distributions/Calculations/Reproducible_fig_5 for PeerJ")
source("/Users/burden/Documents/Next generation sequencing/Paper 2 Overdispersed distributions/Calculations/Reproducible_fig_5 for PeerJ/FDR_and_FPR_Fig_5.R")
setwd("~/Documents/Next generation sequencing/Paper 2 Overdispersed distributions/Calculations/Reproducible_fig_5 for PeerJ")
source("/Users/burden/Documents/Next generation sequencing/Paper 2 Overdispersed distributions/Calculations/Reproducible_fig_5 for PeerJ/FDR_and_FPR_Fig_5.R")
